package xj.graph2d.tree;

import javax.swing.tree.DefaultMutableTreeNode;

import xj.graph2d.Document;
import xj.graph2d.app.project.Project;
import xj.graph2d.app.project.ProjectFolder;
import xj.graph2d.app.project.ProjectItem;
import xj.graph2d.app.project.ProjectType;
import xj.util.StringUtils;

public class ProjectTreeNode 
  extends DefaultMutableTreeNode 
  implements xj.util.gui.TreeNodeToolTips {

  // node types
  public static final int PROJECT_ROOT = 0;

  public static final int PROJECT = 1;

  public static final int PROJECT_FOLDER = 2;

  public static final int PROJECT_ITEM = 3;

  public static final int UML_PROJECT = 10;

  public ProjectTreeNode() {
  }

  public ProjectTreeNode(ProjectItem item) {
    this.item = item;
  }

  public ProjectItem getProjectItem() {
    return item;
  }

  public void setProjectItem(ProjectItem item) {
    this.item = item;
  }

  @Override
  public String toString() {
    if (item instanceof Project) {
      ProjectType projType = ((Project) item).getProjectType();
      if (projType == null) {
	return item.getName();
      } else {
	String projTypeStr = StringUtils.humanize(projType.toString());
	return item.getName() + " [" + projTypeStr + "]";
      }
    } else if (item instanceof ProjectFolder) {
      ProjectFolder.Type folderType = ((ProjectFolder) item).getFolderType();
      if (folderType == null) {
	return item.getName();
      } else {
	String folderTypeStr = StringUtils.humanize(folderType.toString());
	return item.getName() + " [" + folderTypeStr + "]";
      }
    } else if (item instanceof ProjectItem) {
      Document.DocumentType type = item.getItemType();
      if (type == null) {
	return item.getName();
      } else {
	String itemType = StringUtils.humanize(type.toString());
	return item.getName() + " [" + itemType + "]";
      }
    } else {
      return "Projects";
    }
  }

  public int getNodeType() {
    if (item instanceof Project) {
      Project proj = (Project) item;
      if (proj.getProjectType() == ProjectType.UML) { 
	return UML_PROJECT;
      } else { 
	return PROJECT;
      }
    } else if (item instanceof ProjectFolder) {
      return PROJECT_FOLDER;
    } else if (item instanceof ProjectItem) {
      return PROJECT_ITEM;
    } else {
      return PROJECT_ROOT;
    }
  }

  public String getTip() {
    return toString();
  }

  protected ProjectItem item;

}
